package counter.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public final class FileUtils {
    private FileUtils() {
    }

    public static String getFileExtension(File file) {
        return getFileExtension(file.getName());
    }

    public static String getFileExtension(String fileName) {
        int i = fileName.lastIndexOf(DOT);
        return i < 0 ? "" : fileName.substring(i + 1, fileName.length());
    }

    public static int getLoC(File file) {
        int result = 0;
        try {
            BufferedReader br = new BufferedReader(new FileReader(file));
            while (br.readLine() != null) {
                result++;
            }
            br.close();
        } catch (Exception e) {
            throw new IllegalArgumentException("incorrect file name:" + file.getPath());
        }
        return result;
    }

    private final static String DOT = ".";
}
